using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using NUnit.Framework;
using SCSFContrib.CompositeUI.WPF.Workspaces;

namespace SCSFContrib.CompositeUI.WPF.FunctionalTest.Workspaces
{
	[TestFixture]
	public sealed class WindowSmartPartInfoTest : FunctionalTest
	{
		private WindowSmartPartInfo _windowSmartPartInfo;

		protected override void SetUpCore()
		{
			base.SetUpCore();
			_windowSmartPartInfo = new WindowSmartPartInfo();
		}

		[Test]
		[STAThread]
		public void ApplyTo_ShouldApplyPropertiesToGivenWindow()
		{
			Window owner = CreateWindow(null);

			owner.Loaded += delegate
			{
				Style style = new Style();
				Window window = new Window();
				Uri iconUri = new Uri("pack://application:,,,/Workspaces/Test.ico", UriKind.RelativeOrAbsolute);

				//pack URI doesn't appear to be working properly; not sure why
				//IconBitmapDecoder iconBitmapDecoder = new IconBitmapDecoder(iconUri, BitmapCreateOptions.None, BitmapCacheOption.Default);
				//ImageSource icon = iconBitmapDecoder.Frames[0];

				_windowSmartPartInfo.IsModal = true;
				_windowSmartPartInfo.Width = 200;
				_windowSmartPartInfo.Height = 300;
				_windowSmartPartInfo.MinWidth = 50;
				_windowSmartPartInfo.MinHeight = 40;
				_windowSmartPartInfo.MaxWidth = 400;
				_windowSmartPartInfo.MaxHeight = 350;
				_windowSmartPartInfo.Left = 45;
				_windowSmartPartInfo.Top = 55;
				_windowSmartPartInfo.ShowInTaskbar = false;
				_windowSmartPartInfo.IsTopmost = true;
				//_windowSmartPartInfo.Icon = icon;
				_windowSmartPartInfo.ResizeMode = ResizeMode.CanResizeWithGrip;
				_windowSmartPartInfo.SizeToContent = SizeToContent.Height;
				_windowSmartPartInfo.StartupLocation = WindowStartupLocation.CenterOwner;
				_windowSmartPartInfo.State = WindowState.Maximized;
				_windowSmartPartInfo.Style = WindowStyle.None;
				_windowSmartPartInfo.WpfStyle = style;
				_windowSmartPartInfo.Owner = owner;

				_windowSmartPartInfo.ApplyTo(window);

				Assert.AreEqual(200, window.Width);
				Assert.AreEqual(300, window.Height);
				Assert.AreEqual(50D, window.MinWidth);
				Assert.AreEqual(40D, window.MinHeight);
				Assert.AreEqual(400D, window.MaxWidth);
				Assert.AreEqual(350D, window.MaxHeight);
				Assert.AreEqual(45D, window.Left);
				Assert.AreEqual(55D, window.Top);
				Assert.IsFalse(window.ShowInTaskbar);
				Assert.IsTrue(window.Topmost);
				//Assert.AreSame(icon, window.Icon);
				Assert.AreEqual(ResizeMode.CanResizeWithGrip, window.ResizeMode);
				Assert.AreEqual(SizeToContent.Height, window.SizeToContent);
				Assert.AreEqual(WindowStartupLocation.CenterOwner, window.WindowStartupLocation);
				Assert.AreEqual(WindowState.Maximized, window.WindowState);
				Assert.AreEqual(WindowStyle.None, window.WindowStyle);
				Assert.AreSame(style, window.Style);
				Assert.AreSame(owner, window.Owner);

				owner.Close();
			};

			new Application().Run(owner);
		}
	}
}